package com.demo.base.bean;

import java.util.Arrays;

/**
 * 返回客户端状态参数枚举
 * Created by ethan on 2017/1/14.
 */
public class CommonStatus {

    public static final OutputStatus OK = new OutputStatus("OK", "请求已成功");
    public static final OutputStatus BAD_REQUEST = new OutputStatus("BAD_REQUEST", "请求参数有误");
    public static final OutputStatus UNAUTHORIZED = new OutputStatus("UNAUTHORIZED", "当前请求需要用户登录");
    public static final OutputStatus FORBIDDEN = new OutputStatus("FORBIDDEN", "没有访问权限");//服务器已经理解请求，但是拒绝执行它
    public static final OutputStatus NOT_FOUND = new OutputStatus("NOT_FOUND", "找不到请求的资源");//请求失败，请求所希望得到的资源未被在服务器上发现
    public static final OutputStatus SERVER_ERROR = new OutputStatus("SERVER_ERROR", "网络超时，请重试");//服务器遇到了一个未曾预料的状况，导致了它无法完成对请求的处理
//    public static final OutputStatus SERVER_ERROR = new OutputStatus("SERVER_ERROR", "服务器处理过程中出现未处理异常");//服务器遇到了一个未曾预料的状况，导致了它无法完成对请求的处理

    public OutputStatus find(String code) {
        OutputStatus[] values = {
                OK, BAD_REQUEST, UNAUTHORIZED,
                FORBIDDEN, NOT_FOUND, SERVER_ERROR
        };
        return Arrays.stream(values)
                .filter(it -> it.getCode().equals(code))
                .findFirst()
                .orElse(null);
    }
}
